#ifndef _PING_H_
#define _PING_H_
#include <windows.h>

#define		ERROR_PING_NOT_INSTANCE				-2
#define		ERROR_PING_NO_EXIST_HOST			-3
#define		ERROR_PING_NOT_DLL_LOAD				-4
#define		ERROR_PING_ICMP_CREATE_FAILURE		-5
#define		ERROR_PING_NOT_ENOUGHT_MEMORY		-6
#define		ERROR_PING_ICMP_SEND_ERROR			-1

namespace netlib
{
	namespace net
	{
		class Ping
		{
		private:
		struct IP_OPTION_INFORMATION_PING
		{
			unsigned char ttl;
			unsigned char tos;
			unsigned char flags;
			unsigned char optionsSize;
			unsigned char *optionsData;
		} ;

		struct IP_ECHO_REPLY
		{
			DWORD address;                             
			unsigned long  status;                     
			unsigned long  roundTripTime;              
			unsigned short dataSize;                   
			unsigned short reserved;                   
			void *data;                                
			IP_OPTION_INFORMATION_PING options;        
		};

		public:
			Ping( WORD size = 32 );
			virtual ~Ping();

		public:
			int ping( const char *ip, int timeOut = 1000 );

		private:
			HINSTANCE m_icmpInstance;
			IP_ECHO_REPLY *m_pipe;
			char m_ackPingBuffer[ 1024 ];
			WORD m_size;
		};
	}
}

#endif